﻿using System;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using HandyControl.Controls;
using HandyControl.Data;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using YJTMedicalAideManage.Cores.Events;

namespace YJTMedicalAideManage.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        #region 内部字段
        public event Action LoginSuccess;
        private readonly IRegionManager _regionManager;
        #endregion
        public MainWindowViewModel()
        {
            
            SelectCmd = new DelegateCommand<string>(s =>
            {
                Select(s);
            });
        }
        #region 命令
        public DelegateCommand<FunctionEventArgs<object>> SwitchItemCmd => new(SwitchItem);
        public DelegateCommand<string> SelectCmd { get; set; }
        #endregion
        private string selectedTab;

        public string SelectedTab 
        {
            get => selectedTab;
            set
            {
                selectedTab = value;
                RaisePropertyChanged();;

                // 找到第一个空格的位置
                int spaceIndex = selectedTab.IndexOf(' ');

                // 如果空格存在，截取空格之前的部分，否则返回整个字符串
                string headerSubstring = spaceIndex >= 0 ? selectedTab.Substring(0, spaceIndex) : selectedTab;

                Select(headerSubstring);

            }
        }
        #region 方法
        private void SwitchItem(FunctionEventArgs<object> info) => Growl.Info((info.Info as SideMenuItem)?.Header.ToString());
        private void Select(string header)
        {
            switch (header)
            {
                case "医助管理":
                    _regionManager.RequestNavigate("ContentRegion", "MAMView");
                    break;
            }
        }
        #endregion
        private string _title = "Prism Application";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
    }
}
